<template>
  <div class="main-bg">
    <el-tabs v-model="activeName">
      <el-tab-pane label="我的订单" name="first">
        <div class="report-list" v-loading="loading">
          <div class="report-list-item" v-for="item in list" :key="item.id">
            <div class="item-header">
              <div>{{ item.orderItemName }}</div>
              <div>{{ item.validMonth }}个月</div>
            </div>
            <div class="item-time">开通时间：{{ item.startDate }}</div>
            <!-- <div class="item-time">到期时间：{{item.endDate}}</div> -->
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <div class="report-page">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size.sync="currentPageSize"
        :current-page.sync="data.page"
        :total="listTotal"
        @current-change="pageChange"
      >
      </el-pagination>
    </div>

    <share v-model="shareModal" :fid="shareFid"></share>
  </div>
</template>

<script>
import { getOrderList } from "@/api/user.js";
import storage from "@/utils/storage";
import { myFavorite } from "@/api/login.js";
import { mapGetters } from "vuex";
import { shareFile } from "@/api/share.js";
import addGroup from "@/components/addGroup.vue";
import share from "@/components/share.vue";
import {
  AesEncrypt,
  AesDecrypt,
  Base64Encode,
  Base64Decode,
  randomString,
  getRandomKey,
  getSign,
} from "@/utils/aes_util";

const scrollToTop = () => {
  let scrollTop = document.documentElement.scrollTo || document.body.scrollTop;
  if (scrollTop > 0) {
    window.requestAnimationFrame(scrollTop);
    window.scrollTop(0, scrollTop - scrollTo / 8);
  }
};

export default {
  data() {
    return {
      shareModal: false,
      shareFid: "",
      data: {
        page: 1,
        pageSize: 10,
      },
      listTotal: 0,
      list: [],
      currentPageSize: 10,
      activeName: "first",
      infoImg: "",
      infoImgList: [],
      chatName: "",
      listIndex: 0,
      loading: false,
    };
  },
  created() {
    if (process.client) {
      this.getData();
    }
  },
  components: { addGroup, share },
  computed: {
    ...mapGetters(["sid"]),
  },
  watch: {
    activeName: function (n, o) {
      if (n == "first") {
        this.data.op_type = 1;
        this.data.page = 1;
        this.getData();
      }
      if (n == "second") {
        this.data.only_chart = 1;
        this.data.page = 1;
        this.getData();
      }
    },
  },
  methods: {
    getData() {
      this.loading = true;
      getOrderList(this.data.page, this.data.pageSize).then((res) => {
        console.log(res);
        this.list = res.data.data;
        this.listTotal = res.data.count;
        this.loading = false;
      });
    },

    share(item) {
      this.shareFid = item.fid || item.id;
      this.shareModal = true;
    },
    pageChange(page) {
      this.data.page = page;
      this.getData();
      if (process.client) {
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;
      }
    },
  },
};
</script>

<style lang='less' scoped>
.item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.item-time {
  font-size: 14px;
  color: #999;
}

.main-bg {
  width: 720px;
  margin: 0 auto;
  padding-top: 20px;
  min-height: 650px;
}
.report {
  width: 720px;
  margin: 0 auto;
  min-height: 500px;
  &-search {
    margin: 40px 0;
    /deep/ .el-input-group__append {
      background: #467dd0;
      color: #fff;
      width: 96px;
    }
  }
  &-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    &-title {
      font-size: 16px;
      color: #3f4750;
      cursor: pointer;
      // font-weight: bold;
    }
    &-tag {
      &-item {
        margin-left: 8px;
      }
    }
  }
  &-list {
    position: relative;
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
    flex-wrap: wrap;
    padding-top: 14px;
    padding-bottom: 20px;
    &-item {
      padding: 16px 20px 16px;
      width: 100%;
      background: #fff;
      border-radius: 2px;
      border: 1px solid rgba(233, 235, 238, 1);
      margin-top: 12px;
      &-header {
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
        font-size: 16px;
        line-height: 22px;
        &-icon {
          width: 16px;
          height: 16px;
          display: block;
          margin-top: 4px;
          margin-right: 6px;
        }
      }
      &-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 15px;
        &-list {
          display: flex;
          justify-content: flex-start;
          align-items: center;
          font-size: 14px;
          color: #8e969d;
          &-new {
            height: 24px;
            display: block;
            margin-right: 5px;
            width: 24px;
          }
          &-read,
          &-date,
          &-page,
          &-chat {
            margin-right: 20px;
          }
        }
        &-action {
          display: flex;
          justify-content: flex-end;
          align-items: center;
          &-item {
            width: 24px;
            height: 24px;
            display: block;
            margin-left: 16px;
          }
        }
      }
      &-img {
        margin-top: 19px;
        display: flex;
        justify-items: flex-start;
        align-items: center;
        &-item {
          width: 163px;
          height: 163px;
          display: block;
          margin-left: 12px;
          border-radius: 2px;
          display: flex;
          justify-items: center;
          align-items: center;
          &:first-child {
            margin-left: 0;
          }
          img {
            max-width: 100%;
            max-height: 100%;
            display: block;
          }
        }
      }
    }
  }
  &-page {
    width: 100%;
    padding: 15px 0;
    text-align: center;
  }
}
</style>